package com.maple.soa.dao;

import com.maple.soa.mapper.SysRoleMapper;
import com.maple.soa.pojo.SysRole;
import org.mybatis.spring.support.SqlSessionDaoSupport;

import java.util.List;

/**
 * @author lijian
 * @date 2020/7/11
 */
public class SysRoleDaoSupport extends SqlSessionDaoSupport {

    public List<SysRole> listAll() {
        return super.getSqlSession().getMapper(SysRoleMapper.class).listAll();
    }

    public void saveRole(SysRole role) {
        super.getSqlSession().getMapper(SysRoleMapper.class).saveRole(role);
    }

    public void updateRole(SysRole role) {
        super.getSqlSession().getMapper(SysRoleMapper.class).updateRole(role);
    }

    /**
     * 执行事务
     * @param role
     */
    public void saveOrUpdate(SysRole role) {
        super.getSqlSession().getMapper(SysRoleMapper.class).saveRole(role);

        int a = 2 / 0;

        super.getSqlSession().getMapper(SysRoleMapper.class).updateRole(role);
    }

    /**
     * 查询只读，不能执行修改操作
     * @param id
     */
    public void queryRole(Long id) {
        super.getSqlSession().getMapper(SysRoleMapper.class).getById(id);
//        int a = 2 / 0;
        super.getSqlSession().getMapper(SysRoleMapper.class).removeRole(id);
    }
}
